<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="任务名称" prop="task_id">
        <el-select style="width: 108px" size="small" v-model="queryParams.task_id" placeholder="任务名称" clearable>
          <el-option
              v-for="item in tasksList"
              :key="item.id"
              :label="item.task_name"
              :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="机器人名称" prop="robot_id">
        <el-select style="width: 112px" size="small" v-model="queryParams.robot_id" placeholder="机器人名称" clearable>
          <el-option
              v-for="item in robotList"
              :key="item.id"
              :label="item.robot_name"
              :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="巡检点名称" prop="point">
        <el-input  style="width: 90px"
         v-model="queryParams.point"
         placeholder="巡检点"
         clearable
         size="small"
        />
      </el-form-item>
      <el-form-item label="统计分类" prop="state">
          <el-select  style="width: 100px" v-model="queryParams.state" placeholder="统计分类">
            <el-option
                v-for="item in states"
                :key="item.state_type"
                :label="item.state_name"
                :value="item.state_type"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="查询时间">
        <el-date-picker
            v-model="queryParams.create_times"
            style="width: 212px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
     <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
     <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
     <!-- 数据列表区域-->
    <div id="container"  ref="chinaMapChart1" style="height: 250px"></div>
    <div id="container1"  ref="chinaMapChart" style="height: 250px"></div>
  </div>
</template>
<script>
import {delPatrolTaskHIS, listPatrolTasks} from "@/api/robot/patroltask/patroltask";
import {listonPageRobotConfig} from "@/api/robot/robotconfig/robotconfig";
import "@/assets/styles/robt-bg.css";
import {listParamType} from "@/api/robot/paramtype/paramtype";
import * as echarts from 'echarts';
import {AerationPointCount} from "@/api/robot/aerationresult/aerationresult";
let myChart = null;
let myChart1 = null;
export default {
  name: "DiagramData",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //机器人表格数据
      robotList: [],
      // 巡检任务历史表格数据
      patroltaskListHis: [],
      //查询条件区域--初始化参数列表
      alarmParamList:[],
      tasksList:[],
      checkList: [],
      // 弹出层标题
      title: "",
      robot_name: undefined,
      // 是否显示弹出层
      open: false,
      //巡检类型
      states: [
        {state_type:0,state_name:"正常统计"},
        {state_type:1,state_name:"告警统计"}
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        task_id: undefined,
        robot_id: undefined,
        point: undefined,
        state: undefined,
        create_times: [/*this.dealWithTime(new Date()), this.dealWithTime(new Date())*/]
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getrobotList();//机器人列表
    this.gettaskList();//任务列表
    this.getParamList();//查询条件区域
  },
  beforeDestroy() {
    if(myChart != null){myChart.clear();myChart = null;}
    if(myChart1 != null){myChart1.clear();myChart1 = null;}
  },
  methods: {
    getParamList() {
      listParamType(this.queryParams).then(response => {
        this.alarmParamList = response.rows;
      });
    },
    /** 查询机器人列表 */
    getrobotList() {
      this.loading = false;
      listonPageRobotConfig(this.queryParams).then(response => {
        this.robotList = response.rows;
      });
    },
    /** 查询任务列表 */
    gettaskList() {
      this.loading = false;
      listPatrolTasks(this.queryParams).then(response => {
        this.tasksList = response.rows;
      });
    },
    /** 查询巡检任务列表、曲线图表 */
    getList() {
      this.loading = true;
      AerationPointCount(this.queryParams).then(response => {
        let xjds = [];//巡检点
        let bjs = [];//告警统计
        let zcs = [];//正常统计
        if(typeof response.rows !='undefined') {
          let xjdqst = response.rows;//巡检点采集趋势图
          let size_xjdqst = xjdqst.length;
          for(let x=0;x < size_xjdqst;x++) {
            xjds[x] = xjdqst[x].point+"#";//巡检点
            bjs[x] = xjdqst[x].bjs;//告警统计
            zcs[x] = xjdqst[x].zcs;//正常统计
          }
          if(size_xjdqst > 0 ) {
            this.xjdqstqx(xjds, bjs, zcs);//曝气算法巡检点告警数量统计趋势图
            this.xjdqst(xjds, bjs, zcs);//曝气算法巡检点告警数量统计趋势图
          } else {
            this.xjdqstqx([0], [0], [0]);//曝气算法巡检点告警数量统计趋势图
            this.xjdqst([0], [0], [0]);//曝气算法巡检点告警数量统计趋势图
          }
        } else {
          if(myChart != null) myChart.dispose()//销毁echarts
          if(myChart1 != null) myChart1.dispose()//销毁echarts
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        task_name: undefined,
        robot_name:undefined,
        robot_config_id :undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.state = undefined;
      this.queryParams.task_id = undefined;
      this.queryParams.robot_id = undefined;
      this.queryParams.point = undefined;
      this.queryParams.create_times = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.task_names = selection.map(item => item.task_name)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    // 多选框选中点位数据
    handleSelectionChangePatrolPoint(selection) {
      this.point_ids = selection.map(item => item.id)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const task_names =row.task_name || this.task_names
      this.$modal.confirm('是否确认删除任务名称为"' + task_names + '"的数据项？').then(function() {
        return delPatrolTaskHIS(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    // 取消按钮
    cancel1() {
      this.open1 = false;
      this.reset();
    },
    /* 曝气算法巡检点告警数量统计*/
    xjdqstqx(xjds, bjs, zcs){
      setTimeout(() => {
        myChart1 = echarts.init(this.$refs.chinaMapChart1)
        let option;
        option = {
          title: {
            text: '巡检点正常/告警次数统计_曲线图',
            y:'top',
            x:'left',
            textStyle: {
              color: '#273b8d'
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          legend: {
            textStyle: {
              color: "#a4a5a6"
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '1%',
            containLabel: true
          },
          xAxis: [
            {
              axisLine: {
                show: true, // 不显示坐标轴线
                lineStyle: {
                  color: '#0d409f', //x轴的颜色
                }
              },//横坐标值颜色
              axisLabel: {
                show: true,
                textStyle: {
                  color: '#7287ab'
                }
              },
              splitLine: {
                show: false // 不显示网格线
              },
              name:"巡检点",
              type: 'category',
              data: xjds
            }
          ],
          yAxis: [
            {
              axisTick: {
                show: true,  //刻度线
              },
              axisLine: {
                show: true, // 显示坐标轴线
                lineStyle: {
                  color: '#0d409f', //x轴的颜色
                }
              },
              name:"巡检点正常/告警值",
              splitLine: {
                show: false // 不显示网格线
              },
              type: 'value'
            }
          ],
          series: [
            {
              symbol:'circle',//空心点改为实心点
              symbolSize:8,
              smooth: true,
              name: '巡检点正常统计',
              type: 'line',
              itemStyle: {
                color: '#0a51a2' // 设置曲线颜色为红色（十六进制）
              },
              data: zcs,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              }
            }, {
              symbol:'circle',//空心点改为实心点
              symbolSize:8,
              smooth: true,
              name: '巡检点告警统计',
              type: 'line',
              itemStyle: {
                color: '#b01010' // 设置曲线颜色为红色（十六进制）
              },
              data: bjs,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              }
            }
          ]
          , dataZoom: [
            {
              fillerColor:'#0e2e79',
              borderColor:'#1c44a2',
              height:18,
              bottom:18,
              type: 'inside',
              startValue: 0,
              endValue: 17
            },
            {
              fillerColor:'#0e2e79',
              borderColor:'#1c44a2',
              height:18,
              bottom:18,
              startValue: 0,
              endValue: 17
            }
          ]
        };
        if (option && typeof option === 'object') {
          myChart1.setOption(option);
        }
        window.addEventListener("resize", () => {
          if(myChart1!=null)myChart1.resize();
        });
      }  , 1);
    },
   /* 曝气算法巡检点告警数量统计*/
    xjdqst(xjds, bjs, zcs){
      setTimeout(() => {
        myChart = echarts.init(this.$refs.chinaMapChart)
        let option;
        option = {
          title: {
            text: '巡检点正常/告警次数统计_柱状图',
            y:'top',
            x:'left',
            textStyle: {
              color: '#273b8d'
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          legend: {
            textStyle: {
              color: "#a4a5a6"
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '1%',
            containLabel: true
          },
          xAxis: [
            {
              axisLine: {
                show: true, // 不显示坐标轴线
                lineStyle: {
                  color: '#0d409f', //x轴的颜色
                }
              },//横坐标值颜色
              axisLabel: {
                show: true,
                textStyle: {
                  color: '#7287ab'
                }
              },
              splitLine: {
                show: false // 不显示网格线
              },
              name:"巡检点",
              type: 'category',
              data: xjds
            }
          ],
          yAxis: [
            {
              axisTick: {
                show: true,  //刻度线
              },
              axisLine: {
                show: true, // 显示坐标轴线
                lineStyle: {
                  color: '#0d409f', //x轴的颜色
                }
              },
              name:"巡检点正常/告警值",
              splitLine: {
                show: false // 不显示网格线
              },
              type: 'value'
            }
          ],
          series: [
            {
              name: '巡检点正常统计',
              type: 'bar',
              stack: 'Ad',
              itemStyle: {
                color: '#233a96' //设置为红色
              },
              emphasis: {
                focus: 'series'
              },
              data: zcs,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              },
              label: {
                show: true, // 显示标签
                position: 'inside', // 位于顶部
                color:'#7eb9f5'
              }
            },
            {
              name: '巡检点告警统计',
              type: 'bar',
              stack: 'Ad',
              itemStyle: {
                color: '#a11c1c' //设置为红色
              },
              emphasis: {
                focus: 'series'
              },
              data: bjs,
              markPoint: {
                data: [
                  { type: 'max', name: 'Max' },
                  { type: 'min', name: 'Min' }
                ]
              },
              label: {
                show: true, // 显示标签
                position: 'insideTop', // 位于顶部
                color:'#f37f40'
              }
            }
          ]
          , dataZoom: [
            {
              fillerColor:'#0e2e79',
              borderColor:'#1c44a2',
              height:18,
              bottom:18,
              type: 'inside',
              startValue: 0,
              endValue: 17
            },
            {
              fillerColor:'#0e2e79',
              borderColor:'#1c44a2',
              height:18,
              bottom:18,
              startValue: 0,
              endValue: 17
            }
          ]
        };
        if (option && typeof option === 'object') {
          myChart.setOption(option);
        }
        window.addEventListener("resize", () => {
          if(myChart!=null)myChart.resize();
        });
      }  , 1);
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
/**列表添加垂直隐藏滚动条**/
.tabled{
height: 550px;
overflow: hidden;
overflow-y: scroll;
}
.tabled::-webkit-scrollbar {
width: 0 !important;
height: 0 !important;
}
</style>
